home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-12-23 | 3.4 KB | 146 lines | [TEXT/PJMM] |
- unit MyFetchSuffix;
-
- { Thanks to Jim Matthews for allowing me to read his Fetch preference file }
-
- interface
-
- function FetchSuffixInfo (name: str255; var ftype, fcreator: OSType; var binary, binhex: boolean): boolean;
- function IsExtension (name, ext: str255): boolean;
- function GetTextCreator: OSType;
-
- implementation
-
- uses
- Folders;
-
- const
- SuffixResType = 'SUFX';
- SuffixResID = 1;
- old_fetch_prefs_name = 'Fetch Preferences';
- new_fetch_prefs_name = 'Fetch Prefs'; { changed to avoid Aldus Prefs I assume }
-
- { Format: }
- { repeat }
- { type:OSType }
- { creator:OSType }
- { binary:two byte boolean }
- { binhex: two byte boolean }
- { extension:cstring }
- { description:cstring }
- { until end of resource }
-
- type
- formatRecord = record
- ftype: OSType;
- fcreator: OSType;
- binary: integer;
- binhex: integer;
- extension: str255;
- description: str255;
- end;
-
- function GetTextCreator: OSType;
- var
- ftype, fcreator: OSType;
- binary, binhex: boolean;
- begin
- if not FetchSuffixInfo('.txt', ftype, fcreator, binary, binhex) then
- if not FetchSuffixInfo('.text', ftype, fcreator, binary, binhex) then
- fcreator := 'R*ch';
- GetTextCreator := fcreator;
- end;
-
- function IsExtension (name, ext: str255): boolean;
- begin
- IsExtension := IUEqualString(copy(name, length(name) - length(ext) + 1, 255), ext) = 0;
- end;
-
- function FetchSuffixInfo (name: str255; var ftype, fcreator: OSType; var binary, binhex: boolean): boolean;
- var
- p: ptr;
- left: longInt;
- found: boolean;
-
- procedure CheckExt (ext: str255; ft, fc: OSType; bin, hex: boolean);
- begin
- if IsExtension(name, ext) then begin
- found := true;
- ftype := ft;
- fcreator := fc;
- binary := bin;
- binhex := hex;
- end;
- end;
-
- procedure ReadEntry;
- procedure ReadString (var s: str255);
- var
- q: ptr;
- len: longInt;
- begin
- len := 0;
- while p^ <> 0 do begin
- len := len + 1;
- if len <= 255 then
- s[len] := chr(p^);
- p := ptr(ord(p) + 1);
- end;
- p := ptr(ord(p) + 1);
- left := left - len - 1;
- if len > 255 then
- len := 255;
- s[0] := chr(len);
- end;
- var
- ext, desc: str255;
- fr: formatRecord;
- begin
- BlockMove(p, @fr, 12);
- p := ptr(ord(p) + 12);
- left := left - 12;
- ReadString(ext);
- ReadString(desc);
- CheckExt(ext, fr.ftype, fr.fcreator, fr.binary <> 0, fr.binhex <> 0);
- end;
-
- var
- res: integer;
- h: handle;
- fs: FSSpec;
- junk: OSErr;
- goodenough: boolean;
- begin
- ftype := 'BINA';
- fcreator := 'R*ch';
- binary := true;
- binhex := false;
- found := false;
- CheckExt('.hqx', 'TEXT', 'SITx', false, true);
- CheckExt('.txt', 'TEXT', 'R*ch', false, false);
- CheckExt('.sit', 'SITD', 'SITx', true, false);
- CheckExt('.cpt', 'CPCT', 'SITx', true, false);
- goodenough := found;
- found := false;
- junk := FindFolder(kOnSystemDisk, kPreferencesFolderType, true, fs.vRefNum, fs.parID);
- fs.name := new_fetch_prefs_name;
- res := HOpenResFile(fs.vRefNum, fs.parID, fs.name, fsRdPerm);
- if res = -1 then begin
- fs.name := old_fetch_prefs_name;
- res := HOpenResFile(fs.vRefNum, fs.parID, fs.name, fsRdPerm);
- end;
- if res <> -1 then begin
- h := Get1Resource(SuffixResType, SuffixResID);
- if h <> nil then begin
- HLock(h); { Prob not necessary, but who cares }
- p := h^;
- left := GetHandleSize(h);
- while (left > 12) and not found do begin
- ReadEntry;
- end;
- end;
- CloseResFile(res);
- end;
- FetchSuffixInfo := found or goodenough;
- end;
-
- end.